<?php
namespace jy_dayfeeshop;
defined('BY_JYA') or exit('error');
/*
	社区分润计算	
*/
class commission extends \plugin{
	/*
		根据订单生成分润
	*/
	public function get_order($order){
		$api_data=json_decode($order['api_data'],true);
		if(!$order['merchid'] && $api_data['dhmerchid']){
			$this->create_commission($order,$api_data['dhmerchid']);
		}
		return true;
	}
	/*
		给指定带货分红计算分红
	*/
	public function create_commission($order,$dhmerchid=0){
			$dhsettimg=$this->plugin_setting('dhsettimg');
			if(!$dhsettimg['is_opendh'] || !$dhsettimg['dh_pate']){
				return false;
			}
			$total_price=$order['price'];
			$commission_per=$dhsettimg['dh_pate'];
			if(substr($commission_per,-1)=='%'){
				$commission_per=substr($commission_per,0,-1);
				$commission_money=($total_price*$commission_per)/100;
			}else{
				$commission_money=$commission_per;
			}
			$remark=array(
				'order_price'=>$total_price,
				'commission_money'=>$commission_money,
				'commission_per'=>$commission_per,
			);
			$new_commission=array(
				'uniacid'=>$_SESSION['uniacid'],
				'merchid'=>$dhmerchid,
				'orderid'=>$order['id'],
				'money'=>$commission_money,
				'remark'=>ijson_encode($remark),
				'createtime'=>TIMESTAMP,
				'status'=>0,
			);
			pdo_insert('jy_dayfee_commission',$new_commission);
	}
}